package com.taobao.tbk.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class StringRedisUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Value("${redis.expire.time}")
    private Long expireTime;

    public void set(final String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value, expireTime, TimeUnit.SECONDS);
    }

    public String get(final String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    public Boolean exists(final String key) {
        return stringRedisTemplate.hasKey(key);
    }

}
